home *** CD-ROM | disk | FTP | other *** search
-
- ~4Dgifts/toolbox/src/swtools/DSOs compiler-DSOtricks
-
-
-
- Compiler / DSO tricks
-
- 1) DSO's
-
- A dynamic share object (DSO) is an object file that's
- meant to be used simultaneously - or shared - by multiple
- applications (a.out files) while they're executing. You
- can use DSOs in place of archive libraries. By using DSOs,
- you minimize memory use because code is shared. Also, you
- minimize disk use. Executables linked with DSOs are smaller
- than those linked with unshared libraries because the shared
- objects aren't part of the executable file image.
-
- - setenv _RLD_ARGS -v
- It will print each DSO routine by name the
- first time it is called.
-
- -dlopen("libil.so",RTLD_LAZY)
-
- -sgidladd()
- this permits one to dynamically add a library as if
- it has been on the link line - it does NOT require
- one to change code to call indirectly through
- pointers
-
- 2) QuickStart & Conflicts
-
- There seems to be a confusions between quickstart and
- conflicts. The fact that an object has conflicts does not
- mean that it can not quickstart, although if there are
- conflicts rld will have to do more work than if there are
- not. Quickstart fails primarily because the app and the
- objects it will load are out of sync. A typical example is
- you are building an app that links against a dso, libA.so,
- which in turn links against libc.so.1. Now if the
- libc.so.1 on your machine does not match the libc.so that
- was used when building libA.so, your app will be marked as
- non-quickstart by ld. The same holds true when rld runs.
-
- Conflicts deal with overriding behavior in objects that
- will be loaded. For example lets assume that your
- application links against libmalloc.so and libc.so.1. Thus
- it should use the malloc from libmall not libc. However
- there are calls in libc.so.1 to malloc and those have been
- resolved internally to the libc's malloc. Now when running
- the application those references have to be changed to
- point to the malloc routines in libmalloc. That is what
- the conflict list is used for.
-
- 3) Lint
-
- Check out "Writing Solid Code" -- the book which Tom Davis said
- "would change the way he programmed" devotes the first chapter
- to tactics which prevent bugs at compile time. It seems like a
- no-brainer to use -wlint and compile -xansi (the default).
-
-
-
- 4) Improving Program Performance (IRIX System Programming Guide Ch3)
-
- Improving Global Optimization
-
- This section contains coding hints recommended to increase
- optimizing opportunities for the global optimizer (uopt).
- Apply these recommendations to your code whenever
- possible.
-
- C and Fortran Programs
-
- The following suggestion applies to both C and Fortran
- programs:
-
- Do not use indirect calls. Avoid indirect calls (calls that
- use routines or pointers to functions as arguments).
- Indirect calls cause unknown side effects (that is, they
- change global variables) that can reduce the amount of
- optimization possible.
-
- C Programs Only
-
- The following suggestions apply to C programs only:
-
- Return values. Use functions which return values instead of
- pointer parameters.
-
- Do while. Use do while instead of while or for when
- possible. For do while, the optimizer does not have to
- duplicate the loop condition in order to move code from
- within the loop to outside the loop.
-
- Unions. Avoid unions that cause overlap between integer and
- floating point data types. The optimizer will not assign
- such fields to registers.
-
- Use local variables. Avoid global variables. In C programs,
- declare any variable outside of a function as static,
- unless that variable is referenced by another source file.
- Minimizing the use of global variables increases
- optimization opportunities for the compiler.
-
- Value parameters. Pass parameters by value instead of
- passing by reference (pointers) or using global variables.
- Reference parameters have the same degrading effects as the
- use of pointers (see below).
-
- Pointers and aliasing. You can often avoid aliases by
- introducing local variables to store the values obtained
- from dereferenced pointers. Indirect operations and calls
- affect dereferenced values, but do not affect local
- variables. Therefore, local variables can be kept in
- registers. The following example shows how the proper
- placement of pointers and the elimination of aliasing
- produces better code.
-
- 5) prof (IRIX System Programming Guide Ch3)
-
- Use the procedure below to obtain pc sampling information
- (refer to Figure 3-1 ).
-
- 1.Compile the program using the appropriate compiler
- driver. For example, to compile a C program myprog.c:
-
- IRIS% cc -c myprog.c
-
- 2.Link-edit the object file created in Step 1.
-
- IRIS% cc -p -o myprog myprog.o
-
- Note: You must specify the p profiling option during this
- step to obtain pc sampling information.
-
- 3.Execute the profiled program. (During execution,
- profiling data is saved in the file mon.out.)
-
- IRIS% myprog
-
- You can run the program several times, altering the input
- data, to create multiple profile data files. Use the
- environment variable PROFDIR as explained later in this
- section.
-
- 4.Run the profile formatting program prof.
-
- IRIS% prof myprog mon.out
-
- prof extracts information from mon.out and prints it in an
- easily readable format. For more information see the
- prof(1) manual page.
-
- 6) pixie (IRIX System Programming Guide Ch3)
-
- Use the procedure below to obtain basic block counts (refer
- to Figure 3-2 ).
-
- 1.Compile and link edit your program normally. Do not use
- the p option. For example, using the input file myprog.c:
-
- IRIS% cc -o myprog myprog.c
-
- The cc compiler compiles myprog.c into an executable called
- myprog.
-
- 2.Run pixie to generate the equivalent program containing
- basic-block-counting code.
-
- IRIS% pixie myprog -o myprog.pixie
-
- pixie takes myprog and writes an equivalent program
- containing additional code that counts the execution of
- each basic block. pixie also generates a file called
- myprog.Addrs which contains the address of each basic
- block. For more information, refer to the pixie(1) manual
- page.
-
- 3.Execute the file generated by pixie, myprog.pixie, in the
- same way you would execute the original program.
-
- IRIS% myprog.pixie
-
- This program generates a list of basic block counts in a
- file named myprog.Counts.
-
- 4.Run the profile formatting program prof specifying the
- pixie option and the name of the original program.
-
- prof -pixie myprog myprog.Addrs myprog.Counts
-
- prof extracts information from myprog.Addrs and
- myprog.Counts and prints it in an easily readable format.
-